<html>
<head>
<meta charset="UTF-8">
<title>数据运维定时配置新增</title>
	<link id="easyuiTheme"  href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout" style="height:95%;">
	<form id="tt" method="post">
		<div class="esaas-info-title">数据运维mysql配置信息</div>
		<table class="esaas-info-add-table">
			<tr>
				<td width="15%" align="right">MySQL数据库IP：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="baseIP" id="baseIP" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">数据库名称：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="databaseName" id="databaseName" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">用户名：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="userName" id="userName" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">用户密码：</td>
				<td width="35%"><input class="easyui-textbox" type="password"
					name="password" id="password" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">备份路径：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="savePath" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
		</table>
	</form>
	<form id="ff" method="post">
		<div class="esaas-info-title">数据运维定时配置信息</div>
		<table class="esaas-info-add-table">
			<tr>
				<td width="15%"  align="right" hidden>定时作业编号：</td>
				<td width="35%" hidden><input class="easyui-textbox" type="text"
									   name="jobCode" id="jobCode" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">服务节点标识：</td>
				<td width="35%"><input class="easyui-textbox" type="text" buttonText="选择节点"
									   name="agentId" id="agentId" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">Cron表达式：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="cronExpression" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>

			</tr>
			<tr>
				<td width="15%" align="right">作业类类型：</td>
				<td width="35%"><select class="easyui-combobox"
										id="jobClassType" name="jobClassType"
										style="width: 100%; height: 25px;"
										data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:JOB_CLASS_TYPE, onSelect: onChangeJobType">
				</select></td>
				<td width="15%" align="right"><span id="serviceVersionLabel">服务版本：</span></td>
				<td width="35%"><input class="easyui-textbox" type="text" id="serviceVersion"
									   name="serviceVersion" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">作业实现类：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="jobClass" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">作业类方法：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="jobMethod" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right"><span id="serviceGroupLabel">服务组别：</span></td>
				<td width="35%"><input class="easyui-textbox" type="text" id="serviceGroup"
									   name="serviceGroup" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="18%" align="right"><span id="serviceTimeoutLabel">服务超时时间(毫秒)：</span></td>
				<td width="35%"><input class="easyui-textbox" type="text" id="serviceTimeout"
									   name="serviceTimeout" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">失败重试次数：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="againTime" data-options="required:true"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">重试间隔秒数：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="retrySecond" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">作业状态：</td>
				<td width="35%"><select class="easyui-combobox"
										id="jobState" name="jobState"
										style="width: 100%; height: 25px;"
										data-options="required:false,editable:false,valueField:'enname',textField:'cnname',data:JOB_STATE">
				</select></td>
				<td width="15%" align="right">耗时（秒）：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="costTime" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr hidden>
				<td width="15%" align="right">上一次执行时间：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="lastExecuteTime" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">下一次执行时间：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="nextExecuteTime" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>

			<tr>
				<td width="15%" align="right" hidden>所属系统：</td>
				<td width="35%" hidden><input class="easyui-textbox" type="text"
									   name="subsCode" id="subsCode" data-options="required:true,disabled: true"
									   style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">定时作业描述：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
									   name="jobDesc" data-options="required:false"
									   style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">备注：</td>
				<td width="85%" colspan="3"><input class="easyui-textbox" type="text"
												   name="remark" data-options="required:false, multiline: true"
												   style="width: 100%; height: 50px;"></input></td>
			</tr>
		</table>
	</form>
	<div style="text-align: center; padding: 15px">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			onclick="submitForm()">&nbsp;保&nbsp;存&nbsp;</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>
	<script>
		var mysqlNodeId;
		var bpmBaseInfoData;

        $(function() {
        	addTitle("自动备份配置");
            var subsCode=$.getUrlParam('subsCode');
            var bpmCode=$.getUrlParam('bpmCode')+"_mysqlbackup";
            var bpmName=$.getUrlParam('bpmName')+"定时备份服务";
            var queryParams={
                subsCode: subsCode,
                bpmCode:bpmCode,
                bpmName:bpmName,
				latestState:"Y"
            };
			$("#agentId").textbox({
				onClickButton:function (){
					var subsCode = $.getUrlParam("subsCode");
					JLEUtil.createModalWinCustomSize('', 'popSAgentInfoChoice.html',0.8,0.8);
				}
			});

            var rows;
            $.restfulPostForm('../../api/bpm/base/infos/'+1, queryParams, function(data){
                if(data.rows.length==0){
                    $.messager.alert('提示','该自动流程不存在！','info');
                }
                else {
                    for(var i=0;i<data.rows.length;i++)
                        if(data.rows[i].latestState=="Y")
                            bpmBaseInfoData=data.rows[i];
                }
            });
            var srcronJson={jobCode:bpmBaseInfoData.bpmId};
            $.restfulPostForm('../../api/s/srvs/cron/confs/'+subsCode,srcronJson,function(data){
                if(data.rows.length>0){
                    $('#ff').form('load', {
                        jobCode : data.rows[0].jobCode,
                        jobDesc : data.rows[0].jobDesc,
                        jobClassType : data.rows[0].jobClassType,
                        jobClass : data.rows[0].jobClass,
                        jobMethod : data.rows[0].jobMethod,
                        serviceVersion : data.rows[0].serviceVersion,
                        serviceGroup : data.rows[0].serviceGroup,
                        serviceTimeout : data.rows[0].serviceTimeout,
                        cronExpression : data.rows[0].cronExpression,
                        againTime : data.rows[0].againTime,
                        retrySecond : data.rows[0].retrySecond,
                        agentId : data.rows[0].agentId,
                        subsCode:data.rows[0].subsCode,
                        remark : data.rows[0].remark,
                        jobState : data.rows[0].jobState,
                        lastExecuteTime : data.rows[0].lastExecuteTime,
                        nextExecuteTime : data.rows[0].nextExecuteTime,
                        costTime : data.rows[0].costTime
                    });
				}else{
                    var jsonDataAdd = {jobCode:bpmBaseInfoData.bpmId,subsCode: subsCode};
                    $.restfulPostJson('../../api/s/srvs/cron/conf', jsonDataAdd, function(data) {
                    });
                    $("#subsCode").textbox('setValue',$.getUrlParam('subsCode'));
                    $("#jobCode").textbox('setValue',bpmBaseInfoData.bpmId);
				}
            });
            var jsonData = {
                bpmId:bpmBaseInfoData.bpmId,
                bpmNodeCode:'1096'
            };
            $.restfulPostForm('../../api/bpm/node/infos', jsonData, function(data) {
                var returnJsonData  = jQuery.parseJSON(data.rows[0].bpmNodeParam);
                mysqlNodeId = data.rows[0].bpmNodeId;
                if (returnJsonData!=null)
                    $('#tt').form('load', {
                        baseIP : returnJsonData.baseIP,
                        databaseName : returnJsonData.databaseName,
                        userName : returnJsonData.userName,
                        password : returnJsonData.password,
                        savePath : returnJsonData.savePath
                    });
            });
            onChangeJobType(null);
        });

		//执行节点选择返回
		function onChooseAgentId(data){
			if (data){
				$("#agentId").textbox('setValue', data.agentId);
			}else {
				$.messager.alert('提示', '执行节点返回为空！', 'info');
			}
		}

		function submitForm() {
			if (!$('#ff').form('validate')|| !$('#tt').form('validate'))
				return;
			var jsonData = $("#tt").serializeJson();
			var jsonDataTimed=$("#ff").serializeJson();
            jsonData.subsCode=jsonDataTimed.subsCode;
            jsonData.jobCode=jsonDataTimed.jobCode;
            var backupJsonData={
                bpmNodeId:mysqlNodeId,
                bpmNodeParam:JSON.stringify($("#tt").serializeJson()),
            }
            $.restfulPut('../../api/bpm/node/info', backupJsonData, function(data) {
            });
            $.restfulPut('../../api/dbo/backup/conf',jsonData, function(data) {
            });
			$.restfulDelete('../../api/s/srvs/cron/conf', jsonDataTimed, function(data) {
			});
            //5.执行流程发布
            $.ajax({
                type: 'POST',
                url: '../../api/bpm/base/publish/return/bpmId',
                data: JSON.stringify(bpmBaseInfoData),
                contentType:"application/json;charset=utf-8",
                dataType:"json",
                async:false,
                success: function(data) {
                	if ("" != data.rows && data.rows != null){
						jsonDataTimed=$("#ff").serializeJson();
						jsonDataTimed.jobCode = data.rows;
						$.restfulPostJson('../../api/s/srvs/cron/conf', jsonDataTimed, function(data) {
							window.parent.reloadList();
						});

					}
                }
            });
		};

        function onChangeJobType(data){
            console.log(data);
            if(data && (data.enname == 'hsf' || data.enname == 'dubbo')) {
                $("#serviceVersionLabel").show();
                $("#serviceVersion").next().show();
                $("#serviceGroupLabel").show();
                $("#serviceGroup").next().show();
                $("#serviceTimeoutLabel").show();
                $("#serviceTimeout").next().show();

                $("#serviceVersion").textbox('textbox').validatebox({required: true});
            } else {
                $("#serviceVersionLabel").hide();
                $("#serviceVersion").next().hide();
                $("#serviceGroupLabel").hide();
                $("#serviceGroup").next().hide();
                $("#serviceTimeoutLabel").hide();
                $("#serviceTimeout").next().hide();

                $("#serviceVersion").textbox('textbox').validatebox({required: false});
                $("#serviceVersion").textbox('setValue', '');
                $("#serviceGroup").textbox('setValue', '');
                $("#serviceTimeout").textbox('setValue', '');
            }
        }

		function closeForm() {
			window.parent.JLEUtil.closewin();
		}
	</script>
</body>
</html>